<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./art-template.js"></script>
</head>
<body>
    <table>
        <thead>
            <tr>
                <th>id</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>电话</th>
                <th>爱好</th>
                <th>描述</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
    <script id="model" type="text/html">
        {{each data as item}}
        <tr>
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>{{item.age}}</td>
            <td>{{item.phone}}</td>
            <td>{{item.hobby}}</td>
            <td>{{item.descr}}</td>
        </tr>
        {{/each}}
        {{bbb}}
    </script>
    <script>
        // 1.获取数据.发送ajax请求
        var xhr = new XMLHttpRequest();
        xhr.open("GET","01php.php");
        xhr.send();
        xhr.onreadystatechange = function(){
            if(xhr.readyState === 4){
                // console.log(xhr.responseText);
                var aaa = JSON.parse(xhr.responseText);
                console.log(aaa);
                var text = template("model",{data:aaa,bbb:"111"});
                document.querySelector("tbody").innerHTML = text;
            }
        }

    </script>
</body>
</html>